﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Web.Mvc;
using Newtonsoft.Json;

/// <summary>
/// 判断用户是否已经登录-[{error:1001,msg:"未登录"}]
/// </summary>
public class IsLoginJsonAttribute : AuthorizeAttribute
{
    /// <summary>
    /// 判断用户是否已经登录
    /// </summary>
    /// <param name="httpContext"></param>
    /// <returns>[{error:1001,msg:"未登录"}]</returns>
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        var userinfo = LoginModel.User;
        if (userinfo == null || userinfo.Uid == 0)
        {
            Hashtable hash = new Hashtable();
            hash["error"] = 1001;
            hash["msg"] = "未登录！";
            httpContext.Response.ContentType = "json";
            httpContext.Response.Write(JsonConvert.SerializeObject(hash));
            httpContext.Response.End();
            return false;
        }
        return true;
    }
}